<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ include file="/page/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>交易编辑-${appTradePrivate.tradeName }(${appTradePrivate.tradeCode})</title>
<%@ include file="/adapter/adapter-easyui.jsp" %>
<%@ include file="/adapter/adapter-bootstrap.jsp" %>
<%@ include file="/adapter/adapter-lanren.jsp" %>
<link href="${pageContext.request.contextPath}/frontframe/easyui/themes/easyui-extend.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript">

 function save(){
	var str_data=$("#tradeinfo input,textarea").map(function(){
		   return ($(this).attr("name")+'='+$(this).val());
		 }).get().join("&") ;
    $.ajax({
        url:"${ctx}/appFrameTrade/updateAppTradePrivate",
        type: "POST",      
        dataType:"json",
        data: str_data,
        async: false,
        success: function(data) {
        	if(data.flag>0){
	            alert("保存成功！");	
	            //window.location.reload();
        	}
        },
        error: function() {
          alert("error");
        }
      });
	
}

 function  goBack(){
		window.close();
		//window.history.back(-1);
}


 //用一个隐藏的input和select联动来实现选择使用挡板
 function changeUseBaffle(aThis){
		document.getElementById("isUseBaffle").value=aThis.value;
}
 //页面加载时给select预选值
window.onload=function(){
	var isUseBaffle="${appTradePrivate.isUseBaffle}";
	document.getElementById("s_isUseBaffle").value=isUseBaffle;
	var all_options = document.getElementById("s_isUseBaffle").options;
	for (i=0; i<all_options.length; i++){
		if (all_options[i].value == isUseBaffle){
			all_options[i].selected = true;
		}
	}	
}
 
</script>
</head>
<body class="easyui-layout">
	<div data-options="region:'north',border:false" style="height:44px;background:rgb(45, 195, 232);color:#ffffff;padding:2px">
	   <div class="panel-heading">
      <h3 class="panel-title" align="center">
      ${appTradePrivate.tradeName }(${appTradePrivate.tradeCode}) - 交易信息
      </h3>
   </div>
	</div>
	<div data-options="region:'west',split:true,title:'交易基本信息'" style="width:512px;padding:10px;overflow:hidden">
              <form class="form-horizontal" role="form"  id="tradeinfo">
                             <input  id="ds_name" name="tradeId" type="hidden"  value="${appTradePrivate.tradeId }" />
                             <input  id="ds_name" name="appId" type="hidden"  value="${appTradePrivate.appId }" />
                       <div class="form-group">
                          <label class="col-xs-3 control-label" for="tradeCode">交易码：<font color="red">*</font></label>
                          <div class="col-xs-9">
                             <input class="form-control" id="tradeCode" name="tradeCode" type="text"   value="${appTradePrivate.tradeCode }" placeholder=""/>
                          </div>                      
                       </div>
                       <div class="form-group">
                          <label class="col-xs-3 control-label" for="forwardChannelId">转发渠道标识：<font color="red">*</font></label>
                          <div class="col-xs-9">
                             <input class="form-control" id="forwardChannelId" name="forwardChannelId" type="text"   value="${appTradePrivate.forwardChannelId }" placeholder=""/>
                          </div>              
                       </div>
                       <div class="form-group">
                          <label class="col-xs-3 control-label" for="tradeName">交易名称：<font color="red">*</font></label>
                          <div class="col-xs-9">
                             <input class="form-control" id="tradeName" name="tradeName" type="text"    value="${appTradePrivate.tradeName }" placeholder=""/>
                          </div>               
                       </div>
                       <div class="form-group">
                          <label class="col-xs-3 control-label" for="pageId">归属页面：</label>
                          <div class="col-xs-9">
                             <input class="form-control" id="pageId" name="pageId" type="text"    value="${appTradePrivate.pageId}" placeholder=""/>
                          </div>               
                       </div>                                                  
                       <div class="form-group">
                          <label class="col-xs-3 control-label" for="tradeDesc">交易描述：</label>
                          <div class="col-xs-9">
                           
                             <textarea  class="form-control" id="tradeDesc" name="tradeDesc" rows="3">${appTradePrivate.tradeDesc}</textarea>                          
                          </div>
                       </div>
                       <div class="form-group">
                          <label class="col-xs-3 control-label" for="isUseBaffle">是否使用档板：<font color="red">*</font></label>
                          <div class="col-xs-9">
                             <input class="form-control" id="isUseBaffle" name="isUseBaffle" type="hidden"    value="${appTradePrivate.isUseBaffle}"/>
                             <select id="s_isUseBaffle" onchange="changeUseBaffle(this)" class="form-control">
                             	<option value='N'>否</option>
                             	<option value='Y'>是</option>
                             </select>
                          </div>               
                       </div>                        
                       <div class="form-group">
                          <label class="col-xs-3 control-label" for="tradeBaffleData">交易档板数据：</label>
                          <div class="col-xs-9">
                             <textarea  class="form-control" id="tradeBaffleData" name="tradeBaffleData" rows="8">${appTradePrivate.tradeBaffleData}</textarea>                          
                          </div>
                       </div>
                       <div class="form-group">
                          <div class="col-xs-12" align="center">
					         <button type="button" class="btn btn-default"  onclick="save();">&nbsp;&nbsp;保&nbsp;&nbsp;存&nbsp;&nbsp;</button>
					         <button type="button" class="btn btn-default"  onclick="goBack();">&nbsp;&nbsp;关&nbsp;&nbsp;闭&nbsp;&nbsp;</button>
					      </div>
                       </div>                       
                </form>
	</div>
	<div data-options="region:'center',title:'交易输入输出配置'">
<div class="panel panel-default">
   <div class="panel-heading">
      <h3 class="panel-title">
          交易输入配置
      </h3>
   </div>
   <div class="panel-body">	
              	<input type="button" class="btn btn-default"  id="inputButton" value="增加"  onclick="addInput();"/> 
				<input type="button" class="btn btn-default" value="删除"  onclick="deleteTrade();"/><br>
               <table class="table table-bordered" style="" width="100%" cellspacing="1" cellpadding="0" border="0">
				<thead>
					<tr class="active" align="center">
						<td>选择</td>
						<td style="display: none">唯一键</td>
						<td style="display: none">交易唯一标识</td>
						<td style="display: none">交易要素类型</td>
						<td>交易要素代码</td>
						<td>交易要素名称</td>
						<td>上级交易要素代码</td>
						<td>交易数据格式化</td>
						<td>交易数据格式化参数</td>
					</tr>
				</thead>				
				<tbody>	
				<c:forEach items="${listIn}" var="tradeIn"  varStatus="s" >
					<tr  align="center">
						<td><input type="radio" name="check" id="check" value="15"></td>
						<td style="display: none">${tradeIn.recordKey}</td>
						<td style="display: none">${tradeIn.tradeId}</td>
						<td style="display: none">${tradeIn.tradeElementType}</td>
						<td>${tradeIn.tradeElementCode}</td>
						<td>${tradeIn.tradeElementName}</td>
						<td>${tradeIn.tradeAbvElementCode}</td>
						<td><c:choose>
							<c:when test="${tradeIn.tradeDataFormat eq '0'}">    
		                                   	不格式化
		                                </c:when>
							<c:when test="${tradeIn.tradeDataFormat eq '1'}">    
		                                   	常量
		                                </c:when>
							<c:otherwise> 
		                                	${tradeIn.tradeDataFormat}
		                              </c:otherwise>
							</c:choose>
						</td>
						<td>${tradeIn.tradeDataFormatParam}</td>
					</tr>
				</c:forEach>																
				</tbody>
			</table>
	 </div>
	</div>
<div class="panel panel-default">
   <div class="panel-heading">
      <h3 class="panel-title">
          交易输出配置
      </h3>
   </div>
   <div class="panel-body">		
		        <input type="button" class="btn btn-default"  id="outputButton" value="增加"  onclick="addModules();"/> 
				<input type="button" class="btn btn-default" value="删除"  onclick="deleteTrade();"/><br>
              <table class="table table-bordered" style="" width="100%" cellspacing="1" cellpadding="0" border="0">
				<thead>
					<tr class="active" align="center">
						<td>选择</td>
						<td style="display: none">唯一键</td>
						<td style="display: none">交易唯一标识</td>
						<td style="display: none">交易要素类型</td>
						<td>交易要素代码</td>
						<td>交易要素名称</td>
						<td>上级交易要素代码</td>
						<td>交易数据格式化</td>
						<td>交易数据格式化参数</td>						
					</tr>		
				</thead>				
				<tbody>	
					<c:forEach items="${listOut}" var="tradeOut"  varStatus="s" >
					<tr  align="center">
						<td><input type="radio" name="check" id="check" value="15"></td>
						<td style="display: none">${tradeOut.recordKey}</td>
						<td style="display: none">${tradeOut.tradeId}</td>
						<td style="display: none">${tradeOut.tradeElementType}</td>
						<td>${tradeOut.tradeElementCode}</td>
						<td>${tradeOut.tradeElementName}</td>
						<td>${tradeOut.tradeAbvElementCode}</td>
						<td><c:choose>
							<c:when test="${tradeOut.tradeDataFormat eq '0'}">    
		                                   	不格式化
		                                </c:when>
							<c:when test="${tradeOut.tradeDataFormat eq '1'}">    
		                                   	常量
		                                </c:when>
							<c:otherwise> 
		                                	${tradeOut.tradeDataFormat}
		                    </c:otherwise>
							</c:choose>
						</td>
						<td>${tradeOut.tradeDataFormatParam}</td>		
					</tr>
					</c:forEach>																
				</tbody>
			</table>
	</div>
	</div>	
<div class="theme-popover">
     <div class="theme-poptit">
          <a href="javascript:;" title="关闭" class="close">×</a>
          <h3>填写交易配置信息</h3>
     </div>
     <div class="theme-popbod dform">
           <form class="theme-signin" name="loginform" id="tradeInout"  action="" method="post">
                 <li style="list-style-type:none;display:none"> 唯一键&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ：<input  type="text" name="recordKey" value="" size="20" /><br></li>     
                 <li style="list-style-type:none;display:none"> 交易唯一标识：<input  type="text" name="tradeId" readonly="readonly" value="${appTradePrivate.tradeId }" size="40" /><br></li>     
                 <li style="list-style-type:none;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;交易要素类型：<input type="hidden"  id="element_Type" readonly="readonly" name="tradeElementType" value="" size="40" />
                              <select  id="elementType" name="elementType"  onclick="changeValue(this.value)" >
                                  <option value="1" >输入要素</option> 
                                  <option value="2" >输出要素</option> 
                             </select>
                 <br></li>      
                 <li style="list-style-type:none;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;交易要素代码：<input type="text" name="tradeElementCode" value="" size="40" /><br></li>      
                 <li style="list-style-type:none;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;交易要素名称：<input  type="text" name="tradeElementName" value="" size="40" /><br></li>
                 <li style="list-style-type:none;"> &nbsp;&nbsp;&nbsp;&nbsp;上级交易要素代码：<input  type="text" name="tradeAbvElementCode" value="" size="40" /><br></li>
                 <li style="list-style-type:none;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;交易数据格式化：<input  type="text" name="tradeDataFormat" value="" size="40" /><br></li>
                 <li style="list-style-type:none;"> 交易数据格式化参数：<input  type="text" name="tradeDataFormatParam" value="" size="40" /><br></li>
                 <li style="list-style-type:none;" align="center"> <input class="btn btn-primary" type="button" name="submit" value="保存"  onclick="saveInout()" /></li>
           </form>
     </div>
</div>
<div class="theme-popover-mask"></div>
	
	</div>
</body>
</html>
<script type="text/javascript">
jQuery(document).ready(function($) {
	$('#inputButton').click(function(){
		$('.theme-popover-mask').fadeIn(200);
		$('.theme-popover').slideDown(400);
		//$('#elementType').val('1');
		$("#element_Type").attr("value",'1');
		$('#elementType').find("option[value='1']").attr("selected",true); 
	});
	$('#outputButton').click(function(){
		$('.theme-popover-mask').fadeIn(200);
		$('.theme-popover').slideDown(400);
		//$('#elementType').val('2');
		$("#element_Type").attr("value",'2');
		$('#elementType').find("option[value='2']").attr("selected",true); 
	});
	$('.theme-poptit .close').click(function(){
		$('.theme-popover-mask').fadeOut(200);
		$('.theme-popover').slideUp(400);
	});

});

//保存交易输入输出要素
function saveInout(){
	var str_data=$("#tradeInout input").map(function(){
		   return ($(this).attr("name")+'='+$(this).val());
		 }).get().join("&") ;
     $.ajax({
        url:"${ctx}/appTradeInout/saveAppTradeInout",
        type: "POST",      
        dataType:"json",
        data: str_data,
        async: false,
        success: function(data) {
        	if(data.flag>0){
	            alert("保存成功！");	
	            window.location.reload();
        	}
// 	          $.each(data, function(index, element) {
//             window.location.reload();
//          });
        },
        error: function() {
          alert("error");
        }
      }); 
	
}

function  changeValue(element_Type){
	   document.getElementById("element_Type").value=element_Type;	
}

function deleteTrade(){
	if(record_key!=""){
		if(p_del()){	
    $.ajax({
        url:"${ctx}/appTradeInout/delAppTradeInout?recodekey="+record_key,
        type: "POST",      
        dataType:"json",
        async: false,
        success: function(data) {
        	if(data.flag>0){
	            alert("删除成功！");	
	            window.location.reload();
        	}
/* 	          $.each(data, function(index, element) {
             window.location.reload();
          }); */
        },
        error: function() {
          alert("error");
        }
      });
	   }
	}else{
		alert("请先选择要删除的数据！");
	}
}


function p_del() { 
	var msg = "您真的确定要删除吗？\n\n请确认！"; 
	if (confirm(msg)==true){ 
	return true; 
	}else{ 
	return false; 
	} 
}


var preRow = null;
var record_key="";
$('tbody tr').bind('click', function() {

	var rowIndex = $(this).prevAll().length+1;
	if(rowIndex <1) return;
	
	if(preRow != null){
		preRow.removeClass("active");
	}
	$(this).addClass("active");
	preRow = $(this);
	
	record_key=$(this).find("td").eq(1).text();
	// 行单击后事件(传入行号，应用ID,应用名称信息)
	rowClickAfter(rowIndex,
			$(this).find("td").eq(1).text(),
			$(this).find("td").eq(2).text());
});

</script>

